package com.szholly.pro.watergas_server.ps.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Service;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.data.general.RowBase;

/**
 * 地图基础数据查询service
 * @author lin
 *
 */
@Service
public class MapInfoService {
	
	/**
	 * 获取区和街道数据
	 * @return
	 */
	public TwoTuple<List<RowBase>, HashMap<String, List<RowBase>>> getDistrict(){
		String getJdSql = "select "+
						"       t.jdname name,\n" + 
						"		t.xiancode code,"+
						"       t.shape.minx minx,\n" + 
						"       t.shape.miny miny,\n" + 
						"       t.shape.maxx maxx,\n" + 
						"       t.shape.maxy maxy from sde.jd t\n" + 
						"		left join sde.qx t2 on  t2.xiancode = t.xiancode "+
						" order by t2.xiancode";
		
		String getQuSql = " SELECT  t1.shape.minx minx,\n" +
						"		t1.xiancode code,"+
						"       t1.shape.miny miny,\n" +
						"       t1.shape.maxx maxx,\n" +
						"       t1.shape.maxy maxy,\n" +
						"       T1.XIANNAME name FROM  sde.qx t1";

		List<RowBase> quList = DataUtil.getSelectRows(getQuSql, null);
		List<RowBase> jdList = DataUtil.getSelectRows(getJdSql, null);
		
		HashMap<String, List<RowBase>> jdHashMap = new HashMap<>();
		
		for(int i=0;i<jdList.size();i++){
			RowBase jdItem = jdList.get(i);
			String code = jdItem.getSafeString("CODE");
			if (!jdHashMap.containsKey(code)) {
				jdHashMap.put(code, new ArrayList<>());
			}
			jdHashMap.get(code).add(jdItem);
		}
		
		TwoTuple<List<RowBase>, HashMap<String, List<RowBase>>> district = new TwoTuple<List<RowBase>, HashMap<String,List<RowBase>>>(quList,jdHashMap);
		return district;
	}
	
}
